package com.example.order;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@EnableDiscoveryClient
@RestController
@SpringBootApplication
public class OrderApplication {

	@GetMapping("/orders")
	public String index(HttpServletRequest request) {
		return "orders: " + request.getHeader("x-username");
	}

	@GetMapping("/orders/exceptions/{id}")
    public String exception(@PathVariable Long id) {
        System.out.println("------------------------- exception id: " + id + " -------------------------------");
        throw new RuntimeException("exception: " + id);
    }

    @GetMapping("/private")
    public String doPrivate() {
	    return "private resources";
    }

	public static void main(String[] args) {
		SpringApplication.run(OrderApplication.class, args);
	}
}
